from sqlalchemy import Integer, Column, String, Boolean

from ..database import database


class Client(database.Model):
    id = Column(Integer(), primary_key=True)
    name = Column(String(80))
    description = Column(String(300))
    client_id = Column(String(200))
    client_secret = Column(String(200))
    _redirect_uris = Column('redirect_uris', String(800))
    is_confidential = Column(Boolean(), default=False)
    _default_scopes = Column('default_scopes', String(600))

    @property
    def client_type(self):
        if self.is_confidential:
            return 'confidential'
        return 'public'

    @property
    def default_scopes(self):
        if self._default_scopes:
            return self._default_scopes.split()
        return []

    @property
    def redirect_uris(self):
        if self._redirect_uris:
            return self._redirect_uris.split()
        return []

    @property
    def default_redirect_uri(self):
        return self.redirect_uris[0]
